﻿@{
    Layout = "";
}
<table class="adminContent">
    <tr>
        <td>
            <div id="shipping-rate-grid"></div>

            <script>
                $(document).ready(function () {
                    $("#shipping-rate-grid").kendoGrid({
                        dataSource: {
                            type: "json",
                            transport: {
                                read: {
                                    url: "@Html.Raw(Url.Action("Configure", "ShippingFixedRate", new RouteValueDictionary() { { "Namespaces", "Nop.Plugin.Shipping.FixedRateShipping.Controllers" }, { "area", "" } }))",
                                    type: "POST",
                                    dataType: "json"
                                },
                                update: {
                                    url:"@Html.Raw(Url.Action("ShippingRateUpdate", "ShippingFixedRate", new RouteValueDictionary() { { "Namespaces", "Nop.Plugin.Shipping.FixedRateShipping.Controllers" }, { "area", "" } }))",
                                    type: "POST",
                                    dataType: "json"
                                }
                            },
                            schema: {
                                data: "Data",
                                total: "Total",
                                errors: "Errors",
                                model: {
                                    id: "ShippingMethodId",
                                    fields: {
                                        ShippingMethodId: { editable: false, type: "number" },
                                        ShippingMethodName: { editable: false, type: "string" },
                                        Rate: { editable: true, type: "number" }
                                    }
                                }
                            },
                            requestEnd: function (e) {
                                if (e.type == "update") {
                                    this.read();
                                }
                            },
                            error: function (e) {
                                display_kendoui_grid_error(e);
                                // Cancel the changes
                                this.cancelChanges();
                            },
                            serverPaging: true,
                            serverFiltering: true,
                            serverSorting: true
                        },
                        pageable: {
                            refresh: true,
                            numeric: false,
                            previousNext: false,
                            info: false
                        },
                        editable: {
                            confirmation: false,
                            mode: "inline"
                        },
                        scrollable: false,
                        columns: [{
                            field: "ShippingMethodName",
                            title: "@T("Plugins.Shipping.FixedRateShipping.Fields.ShippingMethodName")",
                            width: 400
                        }, {
                            field: "Rate",
                            title: "@T("Plugins.Shipping.FixedRateShipping.Fields.Rate")",
                            width: 200,
                            editor: function (container, options) {
                                $('<input name="' + options.field + '"/>')
                                        .appendTo(container)
                                        .kendoNumericTextBox({
                                            format: "{0:n4}",
                                            decimals: 4
                                        });
                            }
                        }, {
                            command: {name: "edit", text: "@T("Admin.Common.Edit")"},
                            title: "@T("Admin.Common.Edit")",
                            width: 150
                        }]
                    });
                });
            </script>
        </td>
    </tr>
</table>
